package gew.data;

import gew.utils.SqlUtils;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Objects;

public class IndicatorSummaryItemDetail {

    private final static int COUNTRY_ID = 1;
    private final static int COUNTRY_NAME = 2;
    private final static int COUNTRY_URL = 3;
    private final static int INDICATOR_ID = 4;
    private final static int INDICATOR_NAME = 5;
    private final static int INDICATOR_URL = 6;
    private final static int INDICATOR_UOM = 7;
    private final static int INDICATOR_IS_PERCENT = 8;
    private final static int INDICATOR_FREQUENCY = 9;
    private final static int DATA_SOURCE_NAME = 10;
    private final static int PERIOD_NAME = 11;
    private final static int PERIOD_URL = 12;
    private final static int PREV_PERIOD_NAME = 13;
    private final static int VALUE = 14;
    private final static int PREV_VALUE = 15;
    private final static int DECIMAL_DIGITS = 16;
    private final static int VALUE_STR = 17;
    private final static int PREV_VALUE_STR = 18;

    private final int countryId;
    private final String countryName;
    private final String countryUrl;
    private final int indicatorId;
    private final String indicatorName;
    private final String indicatorUrl;
    private final String indicatorUom;
    private final boolean indicatorIsPercent;
    private final String indicatorFrequency;
    private final String dataSourceName;
    private final String periodName;
    private final String periodUrl;
    private final String prevPeriodName;
    private final String valueStr;
    private final String prevValueStr;
    private final boolean hasLink;
    private final boolean hasValue;

    public IndicatorSummaryItemDetail(ResultSet rs) throws SQLException {
        this.countryId = rs.getInt(COUNTRY_ID);
        this.countryName = rs.getString(COUNTRY_NAME);
        this.countryUrl = rs.getString(COUNTRY_URL);
        this.indicatorId = rs.getInt(INDICATOR_ID);
        this.indicatorName = rs.getString(INDICATOR_NAME);
        this.indicatorUrl = rs.getString(INDICATOR_URL);
        this.hasLink = !Objects.equals(this.indicatorUrl, SqlUtils.EMPTY);
        this.indicatorUom = rs.getString(INDICATOR_UOM);
        this.indicatorIsPercent = rs.getBoolean(INDICATOR_IS_PERCENT);
        this.indicatorFrequency = rs.getString(INDICATOR_FREQUENCY);
        this.dataSourceName = rs.getString(DATA_SOURCE_NAME);
        this.periodName = rs.getString(PERIOD_NAME);
        this.periodUrl = rs.getString(PERIOD_URL);
        this.prevPeriodName = rs.getString(PREV_PERIOD_NAME);
        this.valueStr = (this.indicatorIsPercent && !SqlUtils.EMPTY.equals(rs.getString(VALUE_STR)))
                ?  rs.getString(VALUE_STR).concat(SqlUtils.SPACE).concat(this.indicatorUom)
                :  rs.getString(VALUE_STR);
        this.prevValueStr = (this.indicatorIsPercent && !SqlUtils.EMPTY.equals(rs.getString(PREV_VALUE_STR)))
                ?  rs.getString(PREV_VALUE_STR).concat(SqlUtils.SPACE).concat(this.indicatorUom)
                :  rs.getString(PREV_VALUE_STR);
        this.hasValue = rs.getObject(VALUE) != null;
    }

    public int getIndicatorId() {
        return indicatorId;
    }

    public String getCountryName() {
        return countryName;
    }

    public String getCountryUrl() {
        return countryUrl;
    }

    public String getIndicatorName() {
        return indicatorName;
    }

    public String getIndicatorUrl() {
        return indicatorUrl;
    }

    public String getIndicatorUom() {
        return indicatorUom;
    }

    public boolean isIndicatorIsPercent() {
        return indicatorIsPercent;
    }

    public String getIndicatorFrequency() {
        return indicatorFrequency;
    }

    public String getDataSourceName() {
        return dataSourceName;
    }

    public String getPeriodName() {
        return periodName;
    }

    public String getPeriodUrl() {
        return periodUrl;
    }

    public String getPrevPeriodName() {
        return prevPeriodName;
    }

    public int getCountryId() {
        return countryId;
    }

    public String getValueStr() {
        return valueStr;
    }

    public String getPrevValueStr() {
        return prevValueStr;
    }

    public boolean isHasLink() {
        return hasLink;
    }

    public boolean isHasValue() {
        return hasValue;
    }

}
